﻿using ConfExpert.Forms.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevTeam;

namespace ConfExpert.Forms.Depo.Kauf
{
    public partial class BOMs : XForm
    {
        public int CustomerId { get; set; }
        public BOMs(int CustomerId)
        {
            InitializeComponent();
            this.CustomerId = CustomerId;
        }

        private void BOMs_Load(object sender, EventArgs e)
        {
            gvBOM.Init("GetBOM", CustomerId);
            gvBOM.AddDetailGrid(gvBOMLines, "BOMId");

            gvBOM.MakeReadOnly("MaterialNr", "Style", "Sezon");

            gvBOM.MakeColumnInvisible("DosyaAdi", "Brand", "InsertedOn");
            gvBOMLines.MakeColumnInvisible("InsertedOn", "BOMLinesId");

            gvBOM.BestFitColumns();
            gvBOMLines.BestFitColumns();

            bbiSave.ItemClick += bbiSave_ItemClick;
            bbiRefresh.ItemClick += bbiRefresh_ItemClick;

            gvBOM.AddSummary();
            gvBOMLines.AddSummary();

            gvBOM.EnableRowDelete();
            gvBOMLines.EnableRowDelete();
        }

        void bbiRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvBOM.EndEditing();
            gvBOMLines.EndEditing();
            if (gvBOM.Dataset().HasChanges())
                gvBOM.UpdateAll();

            gvBOM.RefreshDataSource("GetBOM", CustomerId);
        }

        void bbiSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvBOM.EndEditing();
            gvBOMLines.EndEditing();
            if (gvBOM.Dataset().HasChanges())
                gvBOM.UpdateAll();
        }
    }
}
